package com.letwal.cmcvnd.me

import android.annotation.SuppressLint
import android.os.Handler
import android.view.View
import androidx.lifecycle.ViewModel
import com.sdk.sun.salesmartyplugin.index.SaleSmartyInit
import com.letwal.cmcvnd.base.BaseActivity
import com.letwal.cmcvnd.databinding.ActivityCustomerServiceBinding
import com.letwal.cmcvnd.enums.PageTagEnum
import com.letwal.cmcvnd.utils.UserStateUtil

@SuppressLint("CustomSplashScreen")
class CustomerServiceActivity : BaseActivity() {

    private lateinit var mActivityBinding: ActivityCustomerServiceBinding

    override fun onBindingViewModel(): List<ViewModel>? {
        val list = mutableListOf<ViewModel>()
        return list
    }

    override fun onBindingViewTag(): String {
        return PageTagEnum.setting.name.uppercase()
    }

    override fun onBindingContentView(): View {
        mActivityBinding = ActivityCustomerServiceBinding.inflate(layoutInflater)
        return mActivityBinding.root
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onContentViewBinded() {
        try {
            //显示dialog
            showLodingDialog()

            //1
            val scriptUrl = "https://assets.salesmartly.com/js/project_29099_30174_1698333750.js"
            SaleSmartyInit.init(this, scriptUrl)

            //2
            SaleSmartyInit.initSaleSmartyView(this)

            //3
            SaleSmartyInit.addSaleSmartyView(mActivityBinding.llChatContent)

            //6
            SaleSmartyInit.closeSaleSmartyView{
                //mActivityBinding.llChatContent.visibility = View.GONE
                println("closeSaleSmartyView")
            }

            //7
            SaleSmartyInit.setUnReadMessagesListener {
                println("setUnReadMessagesListener: $it")
            }

            Handler().postDelayed({
                //4
                SaleSmartyInit.uploadUserMessage(
                    UserStateUtil.mMobile,
                    UserStateUtil.mMobile,
                    "en",
                    "phone",
                    "email",
                    "description"
                )

                //关闭dialog
                dismissLoadingDialog()

                //5
                SaleSmartyInit.openSaleSmartyView{}

            },3000)

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}